/**
 * create by pntrinh87@gmail.com
 * create date 29/11/2010
 */
function TrAnami(){
    this.divroot=0;
    this.bPrev  =0;
    this.bNext  =0;
    this.fnow   =0;
    this.count  =0;
    this.arg    =0;
    this.tabs   = new Array;
    this.init = function(arg)
    {
        var _root=this;
        if(arg.space==undefined)
        {
            arg.space=4;
        }
        this.arg    = arg;
        this.divroot= document.getElementById(arg.id);
        if(arg.h>0)
        {
            this.divroot.style.height=arg.h+"px";
        }
        var Tab = this.divroot.firstChild;
        while (true)
        {            
            if (Tab.className == "slide")
            {   
                Tab.style.position  = 'absolute';
                Tab.style.height    = arg.h+'px';
                Tab.style.width     = arg.w+'px';
                if(this.arg.type!=1)
                {
                    Tab.style.marginLeft=(arg.w*this.count+this.count*arg.space)+"px";                    
                }else
                {
                    Tab.style.marginTop=(arg.h*this.count+this.count*arg.space)+"px";         
                }
                this.count++;
                Tab.onmouseover=function()
                {
                    _root.stopAuto();
                };
                Tab.onmouseout=function()
                {
                    _root.runAuto();
                };
            }
            Tab = Tab.nextSibling;            
            if (Tab == null) {
                break
            }
        }
        if(arg.tabs)
        {
            var dtabs   = document.getElementById(arg.tabs);
            var Tab     = dtabs.firstChild;
            while (true)
            {            
                if (Tab.tagName == "A")
                { 
                    Tab.onclick = function()
                    {
                        _root.go(this.idd);
                    };
                    Tab.idd=_root.tabs.length;
                    _root.tabs[_root.tabs.length] = Tab;
                }
                Tab = Tab.nextSibling;            
                if (Tab == null) {
                    break
                }
            }
        }
        if(arg.idb && arg.idb)
        {        
            this.bPrev  = document.getElementById(arg.idb);
            this.bNext  = document.getElementById(arg.idn);
            this.bPrev.onclick=function(){_root.goFrame(-1)};
            this.bNext.onclick=function(){_root.goFrame(1)};
            if(arg.fix==undefined)
            {                
                this.bPrev.style.marginTop=this.bNext.style.marginTop = (arg.h/2-10)+"px";
                this.bPrev.style.marginLeft="-12px";
                this.bNext.style.marginLeft=(arg.w+arg.space)+"px";
            }
        }
        this.goFrame(0);
        if(arg.autotime>0)
        {
            this.runAuto();
        }
    };
    this.stopAuto=function()
    {
        clearInterval(this.tauto);
    };
    this.runAuto=function()
    {
        var _root=this;
        if(_root.arg.autotime==undefined)return;
        this.stopAuto();
        this.tauto=setInterval(function(){_root.fnow++;if(_root.fnow>_root.count-1){_root.fnow=0}_root.goFrame(0)},_root.arg.autotime);
    };
    this.go     = function(arg)
    {
        this.fnow = arg;
        this.goFrame(0);        
    };
    this.goFrame = function(arg)
    {
       var _root=this;
        this.fnow += arg;
        if(this.fnow<0)
        {
            this.fnow=0;
        }
        else if(this.fnow>=this.count)
        {
            this.fnow   = this.count-1;
        }
        for(i in this.tabs)
        {
            this.tabs[i].className= (i==this.fnow)? 'selected' : '';            
        }
        if(this.fnow==0)
        {
            this.bPrev.className="PrevnAct";
        }
        else
        {
            this.bPrev.className="PrevAct";
        }
        if(this.fnow==this.count-1 || this.count<=1)
        {
            this.bNext.className="NextnAct";
        }else
        {
            this.bNext.className="NextAct";
        }              
        clearInterval(this.tmovet);
        this.tmovet=setInterval(function(){_root.anami()},25);
    };   
    this.anami = function()
    {
        var disc   = ((this.arg.type==1)? this.arg.h : this.arg.w) * this.fnow + this.fnow*this.arg.space;          
        var last   = (this.arg.type==1)? this.divroot.scrollTop : this.divroot.scrollLeft;      
        var cc     = (disc-last)/Math.ceil(((this.arg.type==1)? this.arg.h : this.arg.w)/35);
        cc         = (cc>0)? Math.ceil(cc) : Math.floor(cc);
        if(this.arg.type==1)
        {
            this.divroot.scrollTop+=cc;
            if(this.divroot.scrollTop==disc)
            {
                clearInterval(this.tmovet);
            }
        }else
        {
            this.divroot.scrollLeft+=cc;
            if(this.divroot.scrollLeft==disc)
            {
                clearInterval(this.tmovet);
            }
        }         
    }; 
}